home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
utility
/
rexxalgo.zip
/
TESTALG1.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1996-05-27
|
18KB
|
507 lines
/* REXX **********************************************/
/* */
/* Name.......: TESTALG1.CMD */
/* Function...: Test Rexx-algorithms from the file */
/* RXALGO01.CMD: */
/* 1. Bubble sort */
/* 2. Binary search */
/* 3. Insertion sort */
/* 4. Quick sort */
/* 5. Shell sort */
/* 6. Square root */
/* 7. Translation to lower case */
/* 8. Digital Audio Player (mciRexx) */
/* */
/* Author.....: Janosch R. Kowalczyk */
/* Compuserve: 101572,2160 */
/* */
/* Create date: 26 May 1996 */
/* Version....: 1.0 */
/* */
/* Changes....: No */
/* */
/* Notes......: Start this file with PMREXX to see */
/* the output lines or comment out the */
/* Say statements for Random and Sort */
/* functions */
/* */
/* Made use of GREED. 26 May 1996 / 12:29:24 JRK */
/*****************************************************/
Say 'This file is the test-routine for the sample internal'
Say 'Rexx-subroutines from the file RXALGO01.CMD'
Say 'Start this file with PMREXX to see the output lines'
Say 'or comment out the Say statements of the stem-variable'
Say 'from RandomStem and test-sort calls .'
Say
Say 'Refer to the source code of this file for more'
Say 'informations, please.'
Say
Say 'The sample calls of this routines follows.'
Say 'Press any key to continue. '
If RxFuncQuery('SysLoadFuncs') Then Do
Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
Call SysLoadFuncs
End /* If RxFuncQuery... */
Call CharIn
Call SysCls
/*--------------(Set random numbers)-------------*/
number = 100
Call RandomStem number
search_value = stem.1
/*-----------------(Bubble Sort)-----------------*/
Say
Say 'Test Bubble Sort.'
start = Time(r)
Call BubSort
endTime = Time(r)
Say 'Sort duration:' endTime
/* Following 3 statements can be comment out */
Do i = 1 To stem.0
Say stem.i
End
/*--------------(Duration: 1.630000)-------------*/
/*----------------(Binary Search)----------------*/
Say
Say 'Test Binary Search. Search for:' search_value
start = Time(r)
found = BiSearch(search_value)
endTime = Time(r)
Say 'Search duration:' endTime
If found > 0 Then Say stem.found
Else Say 'Nothing found'
/*--------------(Duration: 0.030000)-------------*/
/*--------------(Set random numbers)-------------*/
number = 100
Call RandomStem number
/*-----------------(Insert Sort)-----------------*/
Say
Say 'Test Insert Sort.'
start = Time(r)
Call InsSort
endTime = Time(r)
Say 'Sort duration:' endTime
/* Following 3 statements can be comment out */
Do i = 1 To stem.0
Say stem.i
End
/*-------------(Duration: 1.590000)--------------*/
/*-------------(Set random numbers)--------------*/
number = 100
Call RandomStem number
/*-----------------(Quick Sort)------------------*/
Say
Say 'Test Quick Sort.'
start = Time(r)
Call QSort
endTime = Time(r)
Say 'Sort duration:' endTime
/* Following 3 statements can be comment out */
Do i = 1 To stem.0
Say stem.i
End
/*-------------(Duration: 0.310000)--------------*/
/*-------------(Set random numbers)--------------*/
number = 100
Call RandomStem number
/*-----------------(Shell Sort)------------------*/
Say
Say 'Test Shell Sort.'
start = Time(r)
Call ShlSort
endTime = Time(r)
Say 'Sort duration:' endTime
/* Following 3 statements can be comment out */
Do i = 1 To stem.0
Say stem.i
End
/*-------------(Duration: 0.880000)--------------*/
/*--------------(Test Square Root)---------------*/
Say
Say 'Sqrt('search_value') =' SqrRoot(search_value)
/*------------(Test To Lower Case)---------------*/
Say
Say ToLower('TEST TO LOWER CASE OF Ä, Ö AND Ü')
/*------------(Test Digital Player)--------------*/
rc = RxFuncAdd('mciRxInit','MCIAPI','mciRxInit')
Init_RC = mciRxInit()
/* Adjust following file name */
Sound_File = 'D:\MMOS2\SOUNDS\bach.mid'
Say
Say 'Sound file:' Sound_File 'is played. Please wait for the end.'
rc = PlayFile(Sound_File)
Call mciRxExit
Exit
/*===============(Internal subroutines)==============*/
/*==================(Binary search)==================*/
/* :-)) */
/* Name.......: BiSearch */
/* */
/* Function...: Search a stem variable for a value */
/* Call parm..: Search value */
/* Returns....: 0 if nothing found */
/* index of the found value */
/* Sample call: found_index = BiSearch(value) */
/* If found_index = 0 Then */
/* Say 'Value' value 'not found!' */
/* Else */
/* Say stem.found_index */
/* */
/* Notes......: The elements to search for must be */
/* saved in the stem named so as the */
/* stem in this Procedure (in this case */
/* "STEM.") */
/* stem.0 must contain the number of */
/* elements in stem. */
/* The stem-variable must be in the */
/* sorted order */
/* */
/* Changes....: No */
/* */
/*===================================================*/
BiSearch: Procedure Expose stem.
Parse Arg value /* Search value */
found = 0 /* Index of the found Item */
bottom = 1 /* Index of the first Item */
top = stem.0 /* Index of the last Item */
/*------------------(Binary Search)------------------*/
Do While found = 0 & top >= bottom
mean = (bottom + top) % 2
If value = stem.mean Then
found = mean
Else If value < stem.mean Then
top = mean - 1
Else
bottom = mean + 1
End /* Do While */
Return found
/*===================(Bubble sort)===================*/
/* :-I */
/* Name.......: BubSort */
/* */
/* Function...: Bubble Sort for a stem variable */
/* Call parm..: No */
/* Returns....: nothing (NULL string) */
/* */
/* Sample call: Call BubSort */
/* */
/* Notes......: The elements to sort for must be */
/* saved in the stem named so as the */
/* stem in this Procedure (in this case */
/* "STEM.") */
/* stem.0 must contain the number of */
/* elements in stem. */
/* */
/* Changes....: No */
/* */
/*===================================================*/
BubSort: Procedure Expose stem.
/*------------(Bubble Sort for the Stem)-------------*/
Do i = stem.0 To 1 By -1 Until flip_flop = 1
flip_flop = 1